<template>
  <!-- 新增编辑弹窗 -->
  <el-dialog :title="dialogTitle" :visible.sync="isShowDialog" :close-on-click-modal="false" width="1000px">
    <form-add-edit ref="formAdd"></form-add-edit>
    <!-- 操作按钮 -->
    <span slot="footer" class="dialog-footer">
      <el-button class="common_btn-white" @click="isShowDialog = false">取消</el-button>
      <el-button class="common_btn-defalut" type="primary" @click="validateForm">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import FormAddEdit from './modules/form-add-edit'
export default {
  components: { FormAddEdit },
  data () {
    return {
      isShowDialog: false, // 是否显示弹窗
      dialogTitle: '新增监测点'
    }
  },
  methods: {
    // 新增数据
    handleAdd (workPointId) {
      if (!workPointId) {
        this.$notify({
          title: '提示',
          message: '获取工点id失败，请刷新重试',
          type: 'error'
        })
        return false
      }
      this.dialogTitle = '新增监测点'
      this.isShowDialog = true
      this.$nextTick(() => {
        this.$refs.formAdd.handleAdd(workPointId)
      })
    },
    // 编辑
    handleEdit (params) {
      this.dialogTitle = '编辑监测点'
      this.isShowDialog = true
      this.$nextTick(() => {
        this.$refs.formAdd.handleEdit(params)
      })
    },
    // 表单校验
    validateForm () {
      return new Promise((resolve, reject) => {
        this.$refs.formAdd.validateForm(resolve, reject)
      }).then(() => {
        this.isShowDialog = false
        this.$emit('update')
      })
    }
  }
}
</script>
